package ${package.Controller};

import ${cfg.PagedResult};
import ${cfg.PageQuery};
import ${cfg.List};
import ${cfg.QueryConditionUtils};
import ${cfg.ResultGenerator};
import ${cfg.Result};
import ${cfg.modelPackage}.${entity}PageParam;
import ${cfg.modelPackage}.${entity}ListParam;
import ${cfg.modelPackage}.${entity}Param;
import ${cfg.voPackage}.${entity}PageVO;
import ${cfg.voPackage}.${entity}ListVO;
import ${cfg.voPackage}.${entity}VO;
import ${cfg.boPackage}.${entity}BO;
import ${cfg.boPackage}.${entity}PageBO;
import ${cfg.boPackage}.${entity}ListBO;
import ${cfg.convertPackage}.${entity}Convert;
import ${package.Service}.${table.serviceName};
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.entityPath!} Controller
    ${table.comment!}
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@RestController
@RequestMapping("/${controllerMappingHyphen}s")
@AllArgsConstructor
@Api(tags = "${table.entityPath!}相关接口")
public class ${table.controllerName} {

    private ${table.serviceName} ${table.entityPath}Service;

    @PostMapping
    @ApiOperation(value = "添加接口")
    public Result<Boolean> save(@RequestBody ${entity}Param ${table.entityPath}Param) {
        return ResultGenerator.status(${table.entityPath}Service.save(${entity}Convert.INSTANCE.convert(${table.entityPath}Param)));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除接口")
    public Result<Boolean> removeById(@PathVariable("id") Long id) {
        return ResultGenerator.status(${table.entityPath}Service.removeById(id));
    }

    @DeleteMapping("/batch-remove")
    @ApiOperation(value = "批量删除接口")
    public Result<Boolean> removeByIds(@RequestParam("ids") List<Integer> ids) {
        return ResultGenerator.status(${table.entityPath}Service.removeByIds(ids));
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "更新接口")
    public Result<Boolean> updateById(@PathVariable("id") Long id,@RequestBody ${entity}Param ${table.entityPath}Param) {
        return ResultGenerator.status(${table.entityPath}Service.updateById(id, ${entity}Convert.INSTANCE.convert(${table.entityPath}Param)));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "查询详情接口")
    public Result<${entity}VO> getById(@PathVariable("id") Long id) {
        ${entity}BO ${table.entityPath}BO = ${table.entityPath}Service.getDetailById(id);
        return ResultGenerator.success(${entity}Convert.INSTANCE.convert(${table.entityPath}BO));
    }

    @GetMapping("/page")
    @ApiOperation(value = "表分页查询接口")
    public Result<PagedResult<${entity}PageVO>> getPageList(${entity}PageParam ${table.entityPath}PageParam, PageQuery query){
        PagedResult<${entity}PageBO> ${table.entityPath}PageBO = ${table.entityPath}Service.getPageList(
                        query,
                        QueryConditionUtils.getQueryCondition(${table.entityPath}PageParam),
                        ${entity}Convert.INSTANCE.convert(${table.entityPath}PageParam));
        return ResultGenerator.success(${entity}Convert.INSTANCE.convert(${table.entityPath}PageBO));
    }

    @GetMapping
    @ApiOperation(value = "表List查询接口")
    public Result<List<${entity}ListVO>> getList(${entity}ListParam ${table.entityPath}ListParam){
        List<${entity}ListBO> ${table.entityPath}ListBO = ${table.entityPath}Service.getList(
                        QueryConditionUtils.getQueryCondition(${table.entityPath}ListParam),
                        ${entity}Convert.INSTANCE.convert(${table.entityPath}ListParam));
        return ResultGenerator.success(${entity}Convert.INSTANCE.convertVoList(${table.entityPath}ListBO));
    }

}